<template>
  <d2-container :class="{ 'page-compact': crud.pageOptions.compact }">
    <!--    <template slot="header">测试页面1</template>-->
    <d2-crud-x
      ref="d2Crud"
      v-bind="_crudProps"
      v-on="_crudListeners"
      @selectDomainInfo="selectDomainInfo"
      @examineRefuse="examineRefuse"
    >
      <div slot="header">
        <crud-search
          ref="search"
          :options="crud.searchOptions"
          @submit="handleSearch"
        />
        <el-button-group>
          <el-button size="small" type="primary" @click="applyFor"
          ><i class="el-icon-plus" /> 申请</el-button
          >
        </el-button-group>
        <crud-toolbar
          :search.sync="crud.searchOptions.show"
          :compact.sync="crud.pageOptions.compact"
          :columns="crud.columns"
          @refresh="doRefresh()"
          @columns-filter-changed="handleColumnsFilterChanged"
        />
      </div>
    </d2-crud-x>
    <div>
      <el-drawer
        title="套餐功能"
        :visible.sync="packageFeaturesMenuShow"
        direction="rtl"
        size="1000px"
        >
        <template slot="title">
          <div>
            当前租户<el-tag>{{packageFeaturesMenuObj?packageFeaturesMenuObj.name:'无'}}</el-tag>
          </div>
        </template>
      </el-drawer>
    </div>
  </d2-container>
</template>

<script>
import * as api from './api'
import { crudOptions } from './crud'
import { d2CrudPlus } from 'd2-crud-plus'
export default {
  name: 'clientApplyFor',
  mixins: [d2CrudPlus.crud],
  data () {
    return {
      packageFeaturesMenuObj: null,
      packageFeaturesMenuShow: false
    }
  },
  methods: {
    getCrudOptions () {
      return crudOptions(this)
    },
    pageRequest (query) {
      return api.GetList(query)
    },
    // 申请通过
    updateRequest (row) {
      row.type = 'pass'
      return api.PostExamine(row)
    },
    // 申请试用
    applyFor () {
      const routeData = this.$router.resolve({ path: '/register' })
      window.open(routeData.href, '_blank') // 打开新标签
    },
    // 查看租户信息
    selectDomainInfo (scope) {
      this.$router.push({ path: '/tenantClient', query: { id: scope.row.client } })
    },
    // 审核拒绝
    examineRefuse (scope) {
      api.PostExamine({ id: scope.row.id, type: 'refuse' }).then(res => {
        this.$message.success('审核已拒绝')
        this.doRefresh({ from: 'load' })
      })
    }
  }
}
</script>
